﻿using System;
using System.Data;
using System.IO;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;

namespace Common
{
    public abstract class StaticClass
    {
        /// <summary>
        /// 弹出客户端警告对话框。模拟javascript的alert
        /// </summary>
        /// <param name="Page">当前的页面的 Page 类，在调用时用 Page 就行了</param>
        /// <param name="msg">要弹出的字符串</param>
        /// <returns> 无返回值</returns>
        public static void Alert(Page Mypage, string msg)
        {
            if (msg == null) return;
            string tempstr = msg.Replace("\"", "\\\"");
            tempstr = tempstr.Replace("\'", "\\\'").Replace("\n", "").Replace("\r", "");
            StringBuilder sb = new StringBuilder("<script Language=\"Javascript\">");
            sb.Append("alert(\"");
            sb.Append(tempstr).Append("\");");
            sb.Append("<").Append("/").Append("script>");

            if (!Mypage.ClientScript.IsStartupScriptRegistered("msgscript"))
                Mypage.ClientScript.RegisterStartupScript(Mypage.GetType(), "msgscript", sb.ToString());
        }

        /// <summary>
        /// 重载弹出信息功能，并重定向
        /// </summary>
        /// <param name="Mypage"></param>
        /// <param name="msg"></param>
        /// <param name="RedirectURL">要定向的页面，如果为空，则到默认主页</param>
        public static void Alert(Page Mypage, string msg, string RedirectURL)
        {
            if (msg == null) return;
            string tempstr = msg.Replace("\"", "\\\"");
            tempstr = tempstr.Replace("\'", "\\\'").Replace("\n", "").Replace("\r", "");
            StringBuilder sb = new StringBuilder("<script Language=\"Javascript\">");
            sb.Append("alert(\"");
            sb.Append(tempstr).Append("\");");
            sb.Append("document.location='" + RedirectURL + "'"); //要定向的页面，如果为空，则到默认主页
            sb.Append("<").Append("/").Append("script>");
            if (!Mypage.ClientScript.IsStartupScriptRegistered("msgscript"))
                Mypage.ClientScript.RegisterStartupScript(Mypage.GetType(), "msgscript", sb.ToString());
        }



        /// <summary>
        /// 运行一段JavaScript 代码。
        /// </summary>
        /// <param name="Mypage">当前的页面的 Page 类，在调用时用 Page 就行了</param>
        /// <param name="script">要运行的 JavaScript 代码</param>
        public static void RunJs(Page Mypage, string script)
        {
            if (script == null) return;
            StringBuilder sb = new StringBuilder("<script Language=\"Javascript\">");
            sb.Append(script);
            sb.Append("</script>");

            if (!Mypage.ClientScript.IsStartupScriptRegistered("msgscript"))
                Mypage.ClientScript.RegisterStartupScript(Mypage.GetType(), "msgscript", sb.ToString());
        }

        public static void AlertAndClose(Page Mypage, string msg)
        {
            if (msg == null) return;
            string tempstr = msg.Replace("\"", "\\\"");
            tempstr = tempstr.Replace("\'", "\\\'").Replace("\n", "").Replace("\r", "");
            StringBuilder sb = new StringBuilder("<script Language=\"Javascript\">");
            sb.Append("alert(\"");
            sb.Append(tempstr).Append("\");");
            sb.Append("window.close();");
            sb.Append("<").Append("/").Append("script>");
            if (!Mypage.ClientScript.IsStartupScriptRegistered("msgscript"))
                Mypage.ClientScript.RegisterStartupScript(Mypage.GetType(), "msgscript", sb.ToString());
        }

        /// <summary>
        /// 弹出对话框，用户确认后，打开一个模式窗口，模式窗口关闭后，主窗口跳转到某一页面；取消的话，返回原窗口，状态不变
        /// </summary>
        /// <param name="Mypage">默认为本页，Page</param>
        /// <param name="msg">确认信息</param>
        /// <param name="ModalDiag">模式窗口的参数，请用''分离各个参数</param>
        /// <param name="RedirectURL">跳转的页面</param>
        public static void Alert(Page Mypage, string msg, string ModalDiag, string RedirectURL)
        {
            if (msg == null) return;
            string tempstr = msg.Replace("\"", "\\\"");
            tempstr = tempstr.Replace("\'", "\\\'").Replace("\n", "").Replace("\r", "");
            StringBuilder sb = new StringBuilder("<script Language=\"Javascript\">");
            sb.Append("if (confirm('" + tempstr + "')) ");
            sb.Append("{window.showModalDialog(" + ModalDiag + ");");
            sb.Append("window.location.href='" + RedirectURL + "';}</script>");
            if (!Mypage.ClientScript.IsStartupScriptRegistered("msgscript"))
                Mypage.ClientScript.RegisterStartupScript(Mypage.GetType(), "msgscript", sb.ToString());
        }

        public static void OpenModalWin(Page Mypage, string Paras)
        {
            if (Paras == null) return;
            StringBuilder sb = new StringBuilder("<script Language=\"Javascript\">");
            sb.Append("window.showModalDialog(" + Paras + ");");
            sb.Append("<").Append("/").Append("script>");
            if (!Mypage.ClientScript.IsStartupScriptRegistered("msgscript"))
                Mypage.ClientScript.RegisterStartupScript(Mypage.GetType(), "msgscript", sb.ToString());

            //string tmpStr = "window.showModalDialog("+Paras+");";
            //Mypage.Response.Write("<script>"+tmpStr+"</script>");
        }

        public static void RefreshLeftFrame(Page Mypage)
        {
            StringBuilder sb = new StringBuilder("<script Language=\"Javascript\">");
            sb.Append("parent.leftFrame.document.location='/left.aspx';");
            sb.Append("</script>");
            Mypage.Response.Write(sb.ToString());
        }


        public static void ModelWin(Page Mypage, string ModalDiag, string RedirectURL)
        {
            StringBuilder sb = new StringBuilder("<script Language=\"Javascript\">");
            sb.Append("window.showModalDialog(" + ModalDiag + ");");
            sb.Append("window.location.href='" + RedirectURL + "';</script>");
            if (!Mypage.ClientScript.IsStartupScriptRegistered("msgscript"))
                Mypage.ClientScript.RegisterStartupScript(Mypage.GetType(), "msgscript", sb.ToString());
        }

        public static void OpenWin(Page Mypage, string Params)
        {
            string tmpStr = "window.open(" + Params + ");";

            Mypage.Response.Write(JsScript(tmpStr));
        }


        public static void OpenWinInCenter(Page Mypage, string pageURL, string pageName, int width, int height, string Params)
        {
            string openScript = "";
            if (Params == "")
                openScript = string.Format("window.open('{0}','{1}','left='+(screen.width-{2})/2+',top='+(screen.height-{3})/2+',width={2},height={3}');", pageURL, pageName, width.ToString(), height.ToString());
            else
                openScript = string.Format("window.open('{0}','{1}','left='+(screen.width-{2})/2+',top='+(screen.height-{3})/2+',width={2},height={3},{4}');", pageURL, pageName, width.ToString(), height.ToString(), Params);

            string script = "";

            //不知为何不能Format
            //script = "if (screen.width < {0} || screen.height < {1}) { alert('你的电脑分辨率至少应该为：{0} X {1}') } else { {2} } ";
            //script = string.Format(script,width.ToString(),height.ToString(),openScript);

            script = "if (screen.width < " + width.ToString() + " || screen.height < " + height.ToString() + ") { alert('你的电脑分辨率至少应该为：" + width.ToString() + " X " + height.ToString() + "'); } else { " + openScript + " } ";

            Mypage.Response.Write(JsScript(script));
        }


        /// <summary>
        /// 组合成Js Script 语句。
        /// </summary>
        /// <param name="S"></param>
        /// <returns></returns>
        public static string JsScript(string S)
        {
            return "<script>" + S + "</script>";
        }


        /// <summary>
        /// 显示一对话自定义的对话框
        /// </summary>
        /// <param name="Mypage"></param>
        /// <param name="Str">参数等，mess为显示的内容，times为显示的时间，urlTrans为要导向到的url</param>
        public static void ShowMessage(Page Mypage, string Str)
        {
            if (Str == null || Str == "") return;
            Mypage.Response.Redirect("NoteMsg.aspx?" + Str);
        }





        /// <summary>
        /// 判断是否包含于
        /// </summary>
        /// <param name="str">子串</param>
        /// <param name="STR">数据串</param>
        /// <returns></returns>
        public static bool IN(string str, string[] STR)
        {
            foreach (string a in STR)
            {
                if (str == a) return true;
            }
            return false;
        }


        /// <summary>
        /// 在同一窗体中打开一新页面。
        /// </summary>
        /// <param name="myPage">当前的页面的 Page 类，在调用时用 Page 就行了</param>
        /// <param name="PageAndPara">根打开的页面及相应的带?的参数。</param>
        public static void OpenPage(Page myPage, string PageAndPara)
        {
            myPage.Response.Redirect(PageAndPara);
        }


        /// <summary>
        /// 得到文件扩展名
        /// </summary>
        /// <param name="FileName">文件名，如.txt</param>
        /// <returns></returns>
        public static string GetFileExtend(string FileName)
        {
            if (FileName.IndexOf(".") < 0)
            {
                return "";
            }
            else
            {
                return FileName.Substring(FileName.LastIndexOf(".")).Trim();
            }
        }


        /// <summary>
        /// 得到文件的文件名部分，即不带路径部分
        /// </summary>
        /// <param name="FileName"></param>
        /// <returns></returns>
        public static string GetEntireFileName(string FileName)
        {
            if (FileName.IndexOf("\\") < 0)
            {
                return FileName;
            }
            else
            {
                return FileName.Substring(FileName.LastIndexOf("\\") + 1).Trim();
            }
        }


        /// <summary>
        /// 判断文件是否存在，必须是完全路径，不能是相对路径
        /// </summary>
        /// <param name="FileName"></param>
        /// <returns></returns>
        public static bool FileExists(string FileName)
        {
            FileInfo fileInfo = new FileInfo(FileName);
            return fileInfo.Exists;

            // (FileAttributes.Directory in fileInfo.Attributes))
        }

        /// <summary>
        /// 将源文件 Copy 到目录文件。
        /// </summary>
        /// <param name="SourceFile">源文件，带全路径</param>
        /// <param name="TargetFile">目标文件，带全路径</param>
        /// <returns></returns>
        public static bool CopyFile(string SourceFile, string TargetFile)
        {
            try
            {
                FileInfo fileInfo = new FileInfo(SourceFile);
                fileInfo.CopyTo(TargetFile);
                return true;
            }
            catch
            {
                return false;
            }

        }

        /// <summary>
        /// 判断给出的字坐串是否为数字.
        /// </summary>
        /// <param name="S"></param>
        /// <returns></returns>
        public static bool IsInt(string S)
        {
            try
            {
                Convert.ToInt32(S);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public static bool IsNumber(string S)
        {
            try
            {
                Convert.ToDecimal(S);
                return true;
            }
            catch
            {
                return false;
            }
        }



        /// <summary>
        /// 在给出的字符串后加上一个数据种子，从一开始，如果最后一位是数字，则在基础上加1。
        /// </summary>
        /// <param name="S"></param>
        /// <returns></returns>
        public static string AddIntSeed(string S)
        {
            if ((S == null) || (S == "")) return "1";
            try
            {
                string sTmp = S.Substring(S.Length - 1);
                if (IsInt(sTmp))
                {
                    int iTmp = (int.Parse(sTmp) + 1);
                    sTmp = S.Substring(0, S.Length - 1) + iTmp.ToString().Trim();
                }
                else
                {
                    sTmp = S + "1";
                }
                return sTmp;
            }
            catch
            {
                return S + "888";
            }
        }


        /// <summary>
        /// 应用所有DataGrid样式
        /// </summary>
        /// <param name="ctr"></param>		
        public static void ApplyAllDataGridStyle(System.Web.UI.Control ctr)
        {
            //用于调试			ctr.Page.Response.Write(ctr.GetType().ToString()+"<br>");

            if (ctr.GetType().ToString() == "System.Web.UI.WebControls.DataGrid")
            {
                DataGrid dg = ctr as DataGrid;
                //清除原有样式
                dg.Style.Clear();
                dg.AlternatingItemStyle.Reset();
                dg.EditItemStyle.Reset();
                dg.ItemStyle.Reset();
                dg.SelectedItemStyle.Reset();
                dg.HeaderStyle.Reset();
                dg.FooterStyle.Reset();
                dg.PagerStyle.Reset();
                //应用新的样式
                dg.CssClass = "DG";
                dg.AlternatingItemStyle.CssClass = "DGAlternatingItemStyle";
                dg.EditItemStyle.CssClass = "DGEditItemStyle";
                dg.ItemStyle.CssClass = "DGItemStyle";
                dg.SelectedItemStyle.CssClass = "DGSelectedItemStyle";
                dg.HeaderStyle.CssClass = "DGHeaderStyle";
                dg.FooterStyle.CssClass = "DGFooterStyle";
                dg.PagerStyle.CssClass = "DGPagerStyle";

                foreach (DataGridItem item in dg.Items)
                {
                    //用于调试　					ctr.Page.Response.Write(item.ItemType.ToString()+"<br>");
                    if (item.ItemType == ListItemType.Item)
                    {
                        //用于调试ctr.Page.Response.Write("mouse"+"<br>");
                        item.Attributes.Add("onmouseover", "javascript:this.className='DGItemMouseover'");
                        item.Attributes.Add("onmouseout", "javascript:this.className='DGItemStyle'");
                    }
                    else if (item.ItemType == ListItemType.AlternatingItem)
                    {
                        //用于调试ctr.Page.Response.Write("mouse"+"<br>");
                        item.Attributes.Add("onmouseover", "javascript:this.className='DGItemMouseover'");
                        item.Attributes.Add("onmouseout", "javascript:this.className='DGAlternatingItemStyle'");
                    }
                    else
                    {//处理选择编辑项在切换后，残留的js控制
                        item.Attributes.Remove("onmouseover");
                        item.Attributes.Remove("onmouseout");
                        //item.Attributes.Clear();
                    }
                }
            }
            if (ctr.HasControls())
            {
                foreach (Control ctrx in ctr.Controls)
                {
                    ApplyAllDataGridStyle(ctrx);
                }
            }
        }


        /// <summary>
        /// 当dataGird插入或删除数据时，自动调整分页及编辑项,并绑定数据
        /// </summary>
        /// <param name="dg">要处理的dataGrid</param>
        /// <param name="dt">数据源dataTable</param>
        /// <param name="IsInsert">处理方式，插入或者删除</param>
        public static void DataGridAutoPage(DataGrid dg, DataTable dt, bool IsInsert)
        {//可能的最后一页页码
            int SourceItemCount = dt.Rows.Count;
            int MaxPageIndex = (int)Math.Ceiling((double)SourceItemCount / dg.PageSize) - 1;
            if (MaxPageIndex != -1) //Added By Cosix
            {
                if (IsInsert)
                {
                    dg.CurrentPageIndex = MaxPageIndex;
                    dg.EditItemIndex = (int)((SourceItemCount - 1) % dg.PageSize);
                }
                else
                {
                    //如果删除的是最后一页唯一一条，则调整CurrentPageIndex
                    if (dg.CurrentPageIndex > MaxPageIndex)
                    {
                        dg.CurrentPageIndex--;
                    }
                    //取消编辑状态
                    dg.EditItemIndex = -1;
                }
            }
            dg.DataSource = dt;
            dt.DefaultView.Sort = null;
            dg.DataBind();
        }

        /// <summary>
        /// 用来加密字符串
        /// </summary>
        /// <param name="pToEncrypt">要加密的字符串</param>
        /// <param name="sKey">密钥，长度为8</param>
        /// <returns>加密后的字符串</returns>
        public static string Encrypt(string pToEncrypt, string sKey)
        {
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();
            //把字符串放到byte数组中  
            //原来使用的UTF8编码，我改成Unicode编码了，不行  
            byte[] inputByteArray = Encoding.Default.GetBytes(pToEncrypt);
            //byte[]  inputByteArray=Encoding.Unicode.GetBytes(pToEncrypt);  

            //建立加密对象的密钥和偏移量  
            //原文使用ASCIIEncoding.ASCII方法的GetBytes方法  
            //使得输入密码必须输入英文文本  
            des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
            des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
            //Write  the  byte  array  into  the  crypto  stream  
            //(It  will  end  up  in  the  memory  stream)  
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();
            //Get  the  data  back  from  the  memory  stream,  and  into  a  string  
            StringBuilder ret = new StringBuilder();
            foreach (byte b in ms.ToArray())
            {
                //Format  as  hex  
                ret.AppendFormat("{0:X2}", b);
            }
            ret.ToString();
            return ret.ToString();
        }

        /// <summary>
        /// 用来解密字符串
        /// </summary>
        /// <param name="pToDecrypt">要解密的字符串</param>
        /// <param name="sKey">密钥，长度为8，要与加密时使用的密钥相同</param>
        /// <returns>解密后的字符串</returns>

        public static string Decrypt(string pToDecrypt, string sKey)
        {
            DESCryptoServiceProvider des = new DESCryptoServiceProvider();

            //Put  the  input  string  into  the  byte  array  
            byte[] inputByteArray = new byte[pToDecrypt.Length / 2];
            for (int x = 0; x < pToDecrypt.Length / 2; x++)
            {
                int i = (Convert.ToInt32(pToDecrypt.Substring(x * 2, 2), 16));
                inputByteArray[x] = (byte)i;
            }

            //建立加密对象的密钥和偏移量，此值重要，不能修改  
            des.Key = ASCIIEncoding.ASCII.GetBytes(sKey);
            des.IV = ASCIIEncoding.ASCII.GetBytes(sKey);
            MemoryStream ms = new MemoryStream();
            CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
            //Flush  the  data  through  the  crypto  stream  into  the  memory  stream  
            cs.Write(inputByteArray, 0, inputByteArray.Length);
            cs.FlushFinalBlock();

            //Get  the  decrypted  data  back  from  the  memory  stream  
            //建立StringBuild对象，CreateDecrypt使用的是流对象，必须把解密后的文本变成流对象  
            StringBuilder ret = new StringBuilder();

            return System.Text.Encoding.Default.GetString(ms.ToArray());
        }

        /// <summary>
        /// 在字符串中按给出的开始及结束字串取子串.
        /// </summary>
        /// <param name="OldStr">原字符串</param>
        /// <param name="StartStr">开始取子串的字符串</param>
        /// <param name="EndStr">结束取子串的字符串</param>
        /// <param name="Nearest">子串是取最近的还是最远的</param>
        /// <returns> 返回开始子串与结束子串(均不含)之间的字符串，
        /// 如果条件不成立，则反回空字符串，如果找不到结束子串，那么取个原串结束为止</returns>
        public static string DenSubstr(string OldStr, string StartStr, string EndStr, bool Nearest)
        {
            int StartIdx = OldStr.IndexOf(StartStr);
            if (StartIdx < 0) StartIdx = 0;
            int EndIdx = 0;
            if (Nearest)
                EndIdx = OldStr.IndexOf(EndStr);
            else
                EndIdx = OldStr.LastIndexOf(EndStr);
            if (EndIdx < 0) EndIdx = OldStr.Length;
            try
            {
                return OldStr.Substring(StartIdx + 1, EndIdx - StartIdx - 1);
            }
            catch
            {
                return "";
            }
        }


        /// <summary>
        /// 在字符串中按从0开始，取子串到第一个出现的结束标至止。
        /// </summary>
        /// <param name="OldStr">要被转换的字符串</param>
        /// <param name="EndStr">结束取子串的字符串</param>
        /// <returns> 返回操作后取得的字符串，如果条件不成立，则反回空字符串</returns>
        public static string DenSubstr(string OldStr, string EndStr)
        {
            int EndIdx = OldStr.IndexOf(EndStr);
            if (EndIdx < 0) EndIdx = OldStr.Length;
            try
            {
                return OldStr.Substring(0, EndIdx);
            }
            catch
            {
                return "";
            }
        }


        public static string AddThousandSeperator(Int64 number, int decimalLength)
        {
            System.Globalization.NumberFormatInfo nfi = new System.Globalization.CultureInfo("zh-cn", false).NumberFormat;
            nfi.NumberDecimalDigits = decimalLength;
            nfi.NumberGroupSeparator = ",";
            return number.ToString("N", nfi);
        }

        public static string AddThousandSeperator(decimal number, int decimalLength)
        {
            System.Globalization.NumberFormatInfo nfi = new System.Globalization.CultureInfo("zh-cn", false).NumberFormat;
            nfi.NumberDecimalDigits = decimalLength;
            nfi.NumberGroupSeparator = ",";
            return number.ToString("N", nfi);
        }

        public static string AddThousandSeperator(double number, int decimalLength)
        {
            System.Globalization.NumberFormatInfo nfi = new System.Globalization.CultureInfo("zh-cn", false).NumberFormat;
            nfi.NumberDecimalDigits = decimalLength;
            nfi.NumberGroupSeparator = ",";
            return number.ToString("N", nfi);
        }


        /// <summary>
        /// 在客户端控制服务端控件的显示/不显示 作者: BillySir
        /// </summary>
        /// <param name="controller">控制者(相应的HTML控件必须有.checked属性)</param>
        /// <param name="aim">受控者</param>
        /// <param name="visible">true - controller.checked==true时显示, 
        /// false - controller.checked==false时显示</param>
        public static void ClientVisible(WebControl controller, WebControl aim, bool visible)
        {
            //if(!controller.Page.IsPostBack)
            controller.Attributes.Add("onclick", "visibleCtl(this," + aim.ClientID + "," + visible.ToString().ToLower() + ");" + controller.Attributes["onclick"]);
            aim.Style["DISPLAY"] = "none";
            string VisibleInit = "<script language=\"javascript\">visibleCtl(document.all." + controller.ClientID + ",document.all." + aim.ClientID + "," + visible.ToString().ToLower() + ");</script>";
            if (!(controller is RadioButton) || ((RadioButton)controller).Checked)
                controller.Page.ClientScript.RegisterStartupScript(controller.Page.GetType(), "VisibleInit" + controller.UniqueID + "_" + aim.UniqueID, VisibleInit);
            controller.Page.ClientScript.RegisterClientScriptBlock(controller.Page.GetType(), "visibleControlFunction", @"
				<script language=""javascript"">
					function visibleCtl(controller,aim,canView){
					  try{
						if(controller.checked==canView){
							aim.style.display='';
						}else{
							aim.style.display='none';
						}
					  }catch(ex){}
					}
				</script>
			");
        }
        public static string clientScriptStart = "<script language=\"javascript\">\r\n<!--";		//注意后面的字符串首行要留空
        public static string clientScriptEnd = "// -->\r\n</script>";
        public static string jscriptPrefix = "javascript:";
        public static void RegisterGetObject(System.Web.UI.Page page)
        {
            string getObject = @"
function getObject(objectId){
	if(document.getElementById)
		return document.getElementById(objectId);
	else if(document.all&&document.all(objectId))
		return document.all(objectId);
	else
		return false;
}
";
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "getObject", clientScriptStart + getObject + clientScriptEnd);
        }
        public static void RegisterClientClick(System.Web.UI.Page page)
        {
            string clientClick = @"
function clientEnter(aimId){
	if (event.keyCode == 13)
	{
		event.returnValue=false;
		event.cancel = true;
		getObject(aimId).click();
	}
}
";
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "clientClick", clientScriptStart + clientClick + clientScriptEnd);
        }
        public static void EnterDefault(WebControl controller, WebControl aim)
        {
            System.Web.UI.Page page = controller.Page;
            RegisterGetObject(page);
            RegisterClientClick(page);
            controller.Attributes.Add("onkeydown", jscriptPrefix + "clientEnter('" + aim.ClientID + "')");
        }
        public static void ShowTip(HtmlControl anchor, HtmlControl div)
        {
            System.Web.UI.Page page = anchor.Page;
            string js = string.Format("<script language=\"javascript\" src=\"{0}/js/ShowTip.js\"></script>\n", SiteUrl(page)) + clientScriptStart + @"
if (IE4)
{
	document.write('<div id=TipBox style=""position: absolute; visibility: hidden; padding: 5px 5px 5px 5px; background-Color: #EEF5FD; border: 1px solid #D7E5F6; z-index: 900"" onMouseover=""keepTip()"" onMousewheel=""keepTip()"" onMouseout=""hideTip()""></div>');
}
else if (NN4)
{
	document.write('<div id=TipBox style=""position: absolute; visibility: hidden; background-Color: #EEF5FD; filter: alpha(Opacity=94); border: 1px solid #D7E5F6; z-index: 900""></div>');
}" + clientScriptEnd;
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "ShowTip", js);
            anchor.Attributes["onmouseover"] = "Tips('" + div.ClientID + "');";
            anchor.Attributes["onMouseOut"] = "hideTip();";
            div.Style["DISPLAY"] = "none";
        }

        public static string SiteUrl(Page page)
        {
            if (page.Request.ApplicationPath == "/")
                return page.Request.Url.Scheme + "://" + page.Request.Url.Authority;
            else
                return page.Request.Url.Scheme + "://" + page.Request.Url.Authority + page.Request.ApplicationPath;
        }

        public static void TextBoxPrompt(TextBox textBox)
        {
            textBox.Attributes.Add("onfocus", "if(this.value=='" + textBox.Text + "'){this.value='';}");
        }

        public static DataTable ListEnum(Type enumType)
        {
            DataTable dt = new DataTable();
            dt.Columns.Add("Text");
            dt.Columns.Add("Value");
            Array values = Enum.GetValues(enumType);
            foreach (Enum value in values)
            {
                DataRow dr = dt.NewRow();
                dr["Text"] = value.ToString();
                dr["Value"] = (int)Enum.Parse(enumType, value.ToString());
                dt.Rows.Add(dr);
            }
            return dt;
        }

        public static DataTable GetAssemblyInfo()
        {
            DataTable dt = BuildDataTable();

            StringBuilder sb = new StringBuilder();
            ///通过GetAssemblies 调用appDomain的所有程序集
            Assembly[] assems = AppDomain.CurrentDomain.GetAssemblies();
            Array.Sort<Assembly>(assems, new Comparison<Assembly>(comparison));
            foreach (Assembly ass in assems)
            {
                string[] infos = ass.FullName.Split(',');
                //反射当前程序集的信息
                DataRow dr = dt.NewRow();
                dr[0] = infos[0];

                bool DynaAssembly = ass.ManifestModule.Name.IndexOf("<") >= 0 || (ass.ManifestModule.Name.ToUpper() != ass.ManifestModule.ScopeName.ToUpper());
                string sLastWriteTime = string.Empty;
                if (!DynaAssembly)
                {
                    FileInfo info = new FileInfo(ass.Location);
                    sLastWriteTime = "LastWriteTime=" + info.LastWriteTime + ",";
                    dr[1] = info.LastWriteTime;

                    dr[2] = Md5.Md5HashFile(ass.Location);
                }

                dr[3] = infos[1].Replace("Version=", "");
                dr[4] = infos[2].Replace("Culture=", "");
                dr[5] = infos[3].Replace("PublicKeyToken=", "");
                dt.Rows.Add(dr);


                sb.Append(ass.FullName.Replace("Version=", "\r\n" + sLastWriteTime + "Version=") + "\r\n");
            }
            return dt;
        }

        private static DataTable BuildDataTable()
        {
            DataTable dt = new DataTable("AssemblysInfo");
            dt.Columns.Add("Name");             //0
            dt.Columns.Add("LastModifyTime", typeof(DateTime));     //1
            dt.Columns.Add("Md5", typeof(string));      //2
            dt.Columns.Add("Version");      //3
            dt.Columns.Add("Culture");      //4
            dt.Columns.Add("PublicKeyToken");       //5
            return dt;
        }

        private static int comparison(Assembly x, Assembly y)
        {
            return string.Compare(x.FullName, y.FullName);
        }


        #region 全角半角转换  by Andy 2009-06-29
        /// <summary>
        /// 半角转全角 A转成Ａ
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string ToSBC(string s)
        {
            char[] c = s.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] == 32)
                {
                    c[i] = (char)12288;
                    continue;
                }
                if (c[i] < 127)
                {
                    c[i] = (char)(c[i] + 65248);
                }
            }
            return new string(c);
        }
        /// <summary>
        /// 全角转半角Ａ转成A
        /// </summary>
        /// <param name="s"></param>
        /// <returns></returns>
        public static string ToDBC(string s)
        {
            char[] c = s.ToCharArray();
            for (int i = 0; i < c.Length; i++)
            {
                if (c[i] == 12288)
                {
                    c[i] = (char)32;
                    continue;
                }
                if (c[i] > 65280 && c[i] < 65375)
                    c[i] = (char)(c[i] - 65248);
            }
            return new string(c);
        }
        #endregion
    }

    public class DatePicker
    {
        public DatePicker(Page page)
        { }
        public void SetTwoControls(TextBox a, TextBox b, TowControlType c)
        {

        }
        public enum TowControlType
        {
            后者必须大于前者 = 1,
            前者必须大于后者 = 2
        }
    }

    /// <summary>
    /// MeizzDate 的C#.Net封装
    /// 举例:
    /// Common.MeizzDate MDate = new Common.MeizzDate(Page);
    /// MDate.Set(this.TextBox1,this.IMG1);		//文本框＋图片
    /// mDate.Set(this.TextBox2);	//文本框
    /// </summary>
    public class MeizzDate
    {
        public MeizzDate(Page page)
        {
            page.ClientScript.RegisterClientScriptBlock(page.GetType(), "meizzDateJs", string.Format(@"<script language=""javascript"" src=""http://{0}js/meizzDate.js"" type=""text/javascript""></script>", page.Request.Url.Authority + page.ResolveUrl("~")));
        }
        public void Set(TextBox textBox, HtmlControl clickControl)
        {
            clickControl.Style["CURSOR"] = "hand";
            clickControl.Attributes.Add("onclick", string.Format("setday(this,{0});", textBox.ClientID));
            clickControl.Attributes.Add("language", "javascript");
        }
        public void Set(TextBox textBox)
        {
            textBox.Attributes.Add("onfocus", "setday(this);");
            textBox.Attributes.Add("language", "javascript");
        }
    }
}
